# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libgpg-error

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.13
pkgrel=1
pkgdesc="Support library for libgcrypt (mingw-w64)"
arch=('any')
url="http://www.gnupg.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gettext")
groups=("${MINGW_PACKAGE_PREFIX}")
options=('staticlibs' 'strip')
source=("ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-${pkgver}.tar.bz2"
        01-mingw32-fix-potomo.mingw.patch
        02-fix-symbollist-on.mingw.patch
        03-fix-config-on.mingw.patch
        04-use-winpthreads.mingw.patch
        05-w32-gen.all.patch)
md5sums=('fe0cfa7e15262ef8fdeee366109e9ff6'
         '4865ce481ec9aa5efc0a4979f197a686'
         'a69b0fd4c8e4ebda9ddeb68e565bf1b1'
         '548dd52dddbea0be326589c6ef4b9a76'
         'a77d289a29962118847295a28959b0d9'
         '88afb1d5ee7de1e8fac36922a088b7f2')

prepare() {
  cd "$srcdir/libgpg-error-$pkgver"
  patch -p1 -i ${srcdir}/01-mingw32-fix-potomo.mingw.patch
  patch -p1 -i ${srcdir}/02-fix-symbollist-on.mingw.patch
  patch -p1 -i ${srcdir}/03-fix-config-on.mingw.patch
  patch -p1 -i ${srcdir}/04-use-winpthreads.mingw.patch
  patch -p1 -i ${srcdir}/05-w32-gen.all.patch
  
  autoreconf -fi
}

build() {
  cd "$srcdir/libgpg-error-$pkgver"
  sed -i "s,EXPORTS,," "src/gpg-error.def.in"
  mkdir -p $srcdir/build-${CARCH} && cd $srcdir/build-${CARCH}
  ../libgpg-error-$pkgver/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --enable-static
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="$pkgdir" install
}
